<template>
	<el-card class="form-container">
		<el-form :model="editForm" ref="editForm" :rules="dataRule" @keyup.enter.native="dataFormSubmitHandle()" label-width="120px">
			<el-form-item label="等级名称" prop="levelName">
				<el-input v-model="editForm.levelName" placeholder="请输入等级名称" readonly></el-input>
			</el-form-item>
			<el-form-item label="等级成长值" prop="growthPoint">
				<el-input v-model="editForm.growthPoint" placeholder="请输入等级需要的成长值"></el-input>
			</el-form-item>
			<el-form-item label="默认等级" prop="isDefaultLevel">
				<el-radio-group v-model="editForm.isDefaultLevel">
					<el-radio :label="1">是</el-radio>
					<el-radio :label="2">否</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item label="免运费标准" prop="freeFreightPoint">
				<el-input v-model="editForm.freeFreightPoint" placeholder="请输入免运费标准"></el-input>
			</el-form-item>
			<el-form-item label="评价获取成长值" prop="commentGrowthPoint">
				<el-input v-model="editForm.commentGrowthPoint" placeholder="请输入每次评价获取的成长值"></el-input>
			</el-form-item>
			<el-form-item label="免邮特权" prop="priviledgeFreeFreight">
				<el-radio-group v-model="editForm.priviledgeFreeFreight">
					<el-radio :label="1">是</el-radio>
					<el-radio :label="2">否</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item label="会员价格特权" prop="priviledgeMemberPrice">
				<el-radio-group v-model="editForm.priviledgeMemberPrice">
					<el-radio :label="1">是</el-radio>
					<el-radio :label="2">否</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item label="生日特权" prop="priviledgeBirthday">
				<el-radio-group v-model="editForm.priviledgeBirthday">
					<el-radio :label="1">是</el-radio>
					<el-radio :label="2">否</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item label="备注" prop="note">
				<el-input v-model="editForm.note" placeholder="请输入备注"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button @click="cancel">取消</el-button>
				<el-button type="primary" @click="update('editForm')">确定</el-button>
			</el-form-item>
		</el-form>
	</el-card>
</template>

<script>
	import {
		findUserLevelDetail,editUserLevel
	} from '@/api/crm/userLevel'
	export default {
		name: 'user-userLevel',
		data() {
			return {
				editForm: {
					levelName: '',
					growthPoint: '',
					isDefaultLevel: '',
					freeFreightPoint: '',
					commentGrowthPoint: '',
					priviledgeFreeFreight: '',
					priviledgeMemberPrice: '',
					priviledgeBirthday: '',
					note: '',
					createTime: '',
					updateTime: '',
				},
				dataRule: {
					levelName: [{
							required: true,
							message: '请输入等级名称',
							trigger: 'blur'
						},
					],
					growthPoint: [{
							required: true,
							message: '请输入等级需要的成长值',
							trigger: 'blur'
						},
					],
					isDefaultLevel: [{
							required: true,
							message: '请输入是否为默认等级 1是 2否',
							trigger: 'blur'
						},
					],
					freeFreightPoint: [{
							required: true,
							message: '请输入免运费标准',
							trigger: 'blur'
						},
					],
					commentGrowthPoint: [{
							required: true,
							message: '请输入每次评价获取的成长值',
							trigger: 'blur'
						},
					],
					priviledgeFreeFreight: [{
							required: true,
							message: '请输入是否有免邮特权 1是 2否',
							trigger: 'blur'
						},
					],
					priviledgeMemberPrice: [{
							required: true,
							message: '请输入是否有会员价格特权 1是2否',
							trigger: 'blur'
						},
					],
					priviledgeBirthday: [{
							required: true,
							message: '请输入是否有生日特权 1是 2否',
							trigger: 'blur'
						},
					],
					
				}
			}
		},
		created() {
			this.editForm.id = this.$route.query.id
			this.view(this.$route.query.id)
		},
		methods: {
			view(val) {
				findUserLevelDetail(val).then(res => {
					console.log(res)
					this.editForm = res.data.responseData
				})
			},
			cancel() {
				this.$router.go(-1)
			},
			update() {
				const set = this.$refs;
				set['editForm'].validate((valid) => {
					if (!valid) {
						return false
					}
					editUserLevel(this.dataForm).then(() => {
						this.$notify({
							title: '修改成功',
							message: '修改成功',
							type: 'success',
							duration: 2000,
							onClose: this.$router.go(-1)
						})
					})
				})
			}
		}
	}
</script>

<style>
</style>
